package filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * Servlet Filter implementation class CalFilter
 */
@WebFilter("/*")
public class CalFilter implements Filter {

	/**
	 * Default constructor.
	 */
	public CalFilter() {
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		long start = System.nanoTime();
		HttpServletRequest req = (HttpServletRequest) request;
		String servletPath = req.getServletPath();
		chain.doFilter(req, response);// 放行
		long end = System.nanoTime();
		System.out.println("地址：" + servletPath + ":" + (end - start) + "毫微秒");

	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
	}

}
